# pybind11 include
# INCS_ROOT = ./src/include
BINC = $(shell python -m pybind11 --include)
PINC = $(shell python3-config --includes)
INCS = $(BINC) $(PINC) -I$(INCS_ROOT)
# SRCS_ROOT = ./src/source
SRCS = $(wildcard $(SRCS_ROOT)/*.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))

CXXFLAGS = -std=c++11 $(INCS)

LFLAGS = -O3 -Wall

CC = @echo "c++ $@"; c++
# PROJ_NAME = $(shell python ./find_proj.py)
TARGET = $(PROJ_NAME)$(shell python3-config --extension-suffix)

NAME = $(firstword $(shell uname -a))
ifeq ($(NAME), "Darwin")
	LFLAGS += -Xlinker -undefined -Xlinker dynamic_lookup -flto=thin 
else
	LFLAGS += -shared $(shell python3-config --ldflags)
endif
PPATH = $(shell python3-config --prefix)
TOROOT = $(shell find $(PPATH)/lib -maxdepth 2 -type d | grep site-packages)

all: $(TARGET)
$(TARGET):$(OBJS)
	$(CC) $(LFLAGS) $^ -o $@ 

%.o: %.cpp
	$(CC) -c -fPIC $(CXXFLAGS) $^ -o $@
	
show:
	@echo $(NAME)
install:
	mv $(TARGET) $(TOROOT)

clean:
	@echo "clean proj..."
	$(foreach ivar, $(OBJS), rm $(ivar))

uninstall:
	rm $(TOROOT)/$(TARGET)